home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch18 / rad386 / radiosit / src / read_n_w.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-21  |  1.6 KB  |  62 lines

  1. #include <stdio.h>
  2.  
  3. #include "GraphicsGems.h"
  4. #include "data_structure.h"
  5. #include "render.h"
  6.  
  7. int write_out_intensity(fl)
  8. FILE *fl;
  9. {
  10.     int i,j,k,n;
  11.     if (fl == NULL) return;
  12.         if (intensity_out_flag==For_Grids_Only){
  13.     fprintf(fl,"%d\n",color_channels);
  14.     fprintf(fl,"%d\n",number_objects); 
  15.     for (i=0; i < number_objects; i++){
  16.         int grid_points=object[i].grid_v_reso*object[i].grid_h_reso;
  17.         fprintf(fl,"%d %d\n",object[i].grid_v_reso,object[i].grid_h_reso);
  18.         for (j=0;j < grid_points; j++){
  19.             for(k=0; k < color_channels; k++)
  20.                 fprintf(fl,"%g ",
  21.                  object[i].grid[j].normalized_flux_density[k]);
  22.             fprintf(fl,"\n");
  23.         }
  24.     }
  25.     }
  26.         else dump_main_surface_illumination_values(fl);
  27. }
  28.  
  29. int read_in_intensity(fl)
  30. FILE *fl;
  31. {
  32.         int i,j,k,n;
  33.     int c,no;
  34.     fscanf(fl,"%d",&c); if (c!=color_channels) 
  35.         error("Different number of channels.");
  36.     fscanf(fl,"%d",&no); if (no!=number_objects) 
  37.         error("Different number of objects.");
  38.     for (i=0; i < number_objects; i++){
  39.         int g1,g2;
  40.         fscanf(fl,"%d%d",&g1,&g2);
  41.         if ((g1!=object[i].grid_v_reso)
  42.             ||(g2!=object[i].grid_h_reso))
  43.             error("Object grid mismatch");
  44.         for (j=0,n=object[i].grid_v_reso*object[i].grid_h_reso;
  45.                         j < n; j++)
  46.             for(k=0; k < color_channels; k++)
  47.               fscanf(fl,"%lg",
  48.               &(object[i].grid[j].normalized_flux_density[k]));
  49.     }
  50.     fclose(fl);
  51. }
  52. int dump_main_surface_illumination_values(fl)
  53. FILE *fl;
  54. {
  55.     int i,k;
  56.     for (i=0; i < number_objects; i++){
  57.         for(k=0; k < color_channels; k++)
  58.                     fprintf(fl,"%g ",object[i].normalized_flux_density[k]);
  59.         fprintf(fl,"\n");
  60.     }
  61. }
  62.